layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;

    //学生预报名审核列表
    var tableIns = table.render({
		  elem: '#examine',
		  url : 'achievement.json',
		  cellMinWidth : 95,
		  page : true,
		  //toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
		  defaultToolbar: ['filter', 'exports', 'print'],
		  limit : 20,
		  limits : [10,15,20,25],
		  id : "examine",
        cols : [[
            {type: "checkbox", fixed:"left", width:50},
            {field: 'id', title: 'ID', width:60, align:"center" ,fixed:"left"},
            // {field: 'userNumber', title: '学号', width:170},
            {field: 'realName', title: '姓名', width:150},
			{field: 'userHobby',title: '方向',align: 'center',width: 170}, 
            {field: 'userSex', title: '性别',  align:'center',width:130},
            {field: 'achievement', title: '成绩',  align:'center',width:130},
            // {field: 'userHobby', title: '浏览权限', align:'center'},
            // {field: 'releaseTop', title: '是否置顶', align:'center', templet:function(d){
            //     return '<input type="checkbox" name="releaseTop" lay-filter="releaseTop" lay-skin="switch" lay-text="是|否" '+d.releaseTop+'>'
            // }},
            // {field: 'userPhone', title: '发布时间', align:'center', minWidth:110, templet:function(d){
            //     return d.releaseTime.substring(0,10);
            // }},
            // {field: 'userBirthday', title: '截止时间', align:'center', minWidth:110, templet:function(d){
            //     return d.endTime.substring(0,10);
            // }},
            {title: '操作', width:205, templet:'#examineBar',align:"center",fixed:"right"}
        ]]
    });

    //批量删除
    $(".delAll_btn").click(function(){
        var checkStatus = table.checkStatus('newsListTable'),
            data = checkStatus.data,
            newsId = [];
        if(data.length > 0) {
            for (var i in data) {
                newsId.push(data[i].newsId);
            }
            layer.confirm('确定删除选中的文章？', {icon: 3, title: '提示信息'}, function (index) {
                // $.get("删除文章接口",{
                //     newsId : newsId  //将需要删除的newsId作为参数传入
                // },function(data){
                tableIns.reload();
                layer.close(index);
                // })
            })
        }else{
            layer.msg("请选择需要删除的文章");
        }
    })

    //报名详情
    function examineDetail(edit){
        var index = layui.layer.open({
            title : "报名详情",
            type : 2,
			area: ['90%', '90%'],
			fixed: false, //不固定
			maxmin: true,
            content : "achievementDetail.html",
            success : function(layero, index){
                var body = layui.layer.getChildFrame('body', index);
                if(edit){
                    body.find(".realName").val(edit.realName);
                    body.find(".userNumber").val(edit.userNumber);
                    body.find(".userSex").attr("src",edit.userSex);
                    body.find(".userPhone").val(edit.userPhone);
                    body.find(".userBirthday").val(edit.userBirthday);
                    body.find(".userEmail").val(edit.userEmail);
                    body.find(".myself").val(edit.myself);
                    body.find(".achievement").val(edit.achievement);
                    // body.find(".openness input[name='openness'][title='"+edit.newsLook+"']").prop("checked","checked");
                    // body.find(".newsTop input[name='newsTop']").prop("checked",edit.newsTop);
                    form.render();
                }
                setTimeout(function(){
                    layui.layer.tips('点击此处返回文章列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                },500)
            }
        })
    }
     //列表操作
     table.on('tool(examine)', function(obj){
        var layEvent = obj.event,
            data = obj.data;
			console.log(obj)
        if(layEvent === 'detail'){ //编辑
            examineDetail(data);
        } else if(layEvent === 'del'){ //删除
            layer.confirm('确定删除此文章？',{icon:3, title:'提示信息'},function(index){
                // $.get("删除文章接口",{
                //     newsId : data.newsId  //将需要删除的newsId作为参数传入
                // },function(data){
                    tableIns.reload();
                    layer.close(index);
                // })
            });
        } 
    });

})